package com.bk.ouat.controller;

import java.util.List;
import java.util.Map;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.bk.ouat.dto.StoryDto;
import com.bk.ouat.service.StoryService;

/**
 * Handles requests for the application home page.
 */
@Controller
public class StoryController {
	
	private static final Logger logger = LoggerFactory.getLogger(StoryController.class);
	
	@Autowired
	private StoryService storyService;
	
	@RequestMapping(value = "story/list.do")
	public String list(Model model, StoryDto storyDto) {
		List<StoryDto> storyList = storyService.listByCategoryId(storyDto.getCategory_id());
		String headerName = storyService.getHeaderNameByCategoryId(storyDto.getCategory_id());
		model.addAttribute("storyList", storyList);
		model.addAttribute("headerTitle", headerName+" 목록");
		return "story/list";
	}
	
	@RequestMapping(value = "story/detail.do")
	public String detail(Model model, StoryDto storyDto) {
		StoryDto storyDetail = storyService.detail(storyDto);
		model.addAttribute("story", storyDetail);
		model.addAttribute("headerTitle", storyDetail.getTitle());
		return "story/info";
	}
	
}
